{% load static %}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>拍照主页</title>
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <!-- Bootstrap 核心CSS文件 -->
    <link href="{% static 'login/css/bootstrap.min.css' %}" rel="stylesheet">
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <!-- Custom styles for this template -->
    <link href="justified-nav.css" rel="stylesheet">
    <style type="text/css">
      body{
        background: url("{% static 'login/image/3453.jpg' %}");
        background-size: cover;
        background-color: white;
        color: #337ab7;
        }
        /*.form-signin{background: rgba(255,255,255,0);width:320px;margin:120px auto;}*/
        /*阴影*/
        .fa{display: inline-block;top: 27px;left: 6px;position: relative;color: #ccc;}
        input[type="text"],input[type="password"]{padding-left:26px;}
        #checkbox{padding-left:21px;}
        
        .form-signin-heading{
            text-align: center;
            color: #337ab7;
        }
        .tabbable{
            background: rgba(255,255,255,0.7);
        }
        .one{
            width: 100%;
            height: 450px;
            line-height: 450px;
        }
        .footer{
            
            position: fixed;
            left: 460px;
            bottom: 6px;
            background: rgba(255,255,255,0.7);
        }
        .footer .foot{
            margin: 0 auto;
        }
        .btn{
            width: 120px;
            height: 100px;
            margin-left: 96px;
        }
  </style>

</head>
<body>
        <canvas id="canvasCemara" width="500" height="500"></canvas>
        <video autoplay="" id="video2" style="width:500px;height:500px;"></video>
        <button id="btn" >拍摄</button>
        <form action="{%url 'face:face_demand2'%}" method="post" id="img_form">
            <input type="text" name="id" value="{{id}}" style="display: none;">
            <input type="hidden" id="img_inp" name = 'xx' value = '无效'>
            <input type="submit" id="btn02" style="color: red" value="提交并查询"></input>
        </form>
        <footer class="footer">
        <p class="foot">&copy; 2018 北京网络职业学院考试系统Company, Inc.</p>
        </footer>

<script type="text/javascript" src="{% static 'login/js/jquery-3.3.1.min.js' %}"></script>
<!-- Bootstrap部分： -->
<script type="text/javascript" src="{% static 'login/js/bootstrap.min.js' %}"></script>
<script>
var video = document.getElementById('video2');
var constraints = {audio: false, video: true};
 function successCallback(stream) {
     video.srcObject = stream;
     video.play();
 }
 function errorCallback(error) {
     console.log("navigator.getUserMedia error: ", error);
     $(".CameraTips").show();
 }

 navigator.mediaDevices.getUserMedia(constraints)
     .then(successCallback)
     .catch(errorCallback);

document.getElementById("btn").addEventListener("click", function () {
    var video = document.getElementById('video2');
    canvas = document.getElementById('canvasCemara');
    ctx = canvas.getContext('2d');
    var _w = 624, _h = 468;
    if (video.videoWidth > 0) _h = video.videoHeight / (video.videoWidth / _w);
    canvas.setAttribute('width', _w);
    canvas.setAttribute('height', _h);
    ctx.fillRect(0, 0, _w, _h);
    ctx.drawImage(video, 0, 0, _w, _h);
});
document.getElementById("btn02").addEventListener("click", function () {
    var img_data=document.getElementById("canvasCemara");
    var img_base=img_data.toDataURL("image/jpeg");
    document.getElementById("img_inp").value=img_base;
})
</script>
</body>
</html>